package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description:
 * @Version: V1.0
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public boolean save(User user) {
        return userMapper.save(user);
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @Override
    public boolean update(User user) {
        return userMapper.update(user);
    }

    /**
     * 删除用户
     *
     * @param uuid
     * @return
     */
    @Override
    public boolean delete(Integer uuid) {
        return userMapper.delete(uuid);
    }

    /**
     * 查询单个用户信息
     *
     * @param uuid
     * @return
     */
    @Override
    public User get(Integer uuid) {
        return userMapper.get(uuid);
    }

    /**
     * 分页查询
     *
     * @param page 当前页 从1开始
     * @param size 每页显示条数
     * @return
     */
    @Override
    public Page<User> getAll(Integer page, Integer size) {
        /*使用分页插件*/
        PageHelper.startPage(page,size);
        Page<User> pageList = (Page<User>) userMapper.getAll();
        return pageList;
    }


    /**
     * 根据用户名密码查询个人信息
     *
     * @param userName 用户名
     * @param password 密码信息
     * @return
     */
    @Override
    public User login(String userName, String password) {
        return userMapper.getByUserNameAndPassword(userName,password);
    }
}
